1 <?php
2 session_start();
// Use session variable on this page. This function must put on the top of page.
3 if
(!isset($_SESSION['username']) || $_SESSION['usertype'] !='admin'){ // if session variable "username" does not exist.
4 header(
"location:index.php?msg=Please%20login%20to%20access%20admin%20area%20!"); // Re-direct to index.php
5 }

6 else

7 {

8 if
(isset($_GET['from_sales_date']) && isset($_GET['to_sales_date']) && $_GET['from_sales_date']!='' && $_GET['to_sales_date']!='' )
9 {
10     include_once
"db.php";
11     error_reporting (E_ALL ^ E_NOTICE);
12             $selected_date=$_GET[
'from_sales_date'];
13             $selected_date=strtotime( $selected_date );
14             $mysqldate = date(
'Y-m-d H:i:s', $selected_date );
15 $fromdate=$mysqldate;
16             $selected_date=$_GET[
'to_sales_date'];
17             $selected_date=strtotime( $selected_date );
18             $mysqldate = date(
'Y-m-d H:i:s', $selected_date );
19
20 $todate=$mysqldate;
21
22 ?>
23 <!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN"
24 "http:
//www.w3.org/TR/html4/loose.dtd">
25 <html>
26 <head>
27 <title>Sale Report</title>
28 <meta http-equiv=
"Content-Type" content="text/html; charset=iso-8859-1">
29 </head>
30 <style type=
"text/css" media="print">
31 .hide{display:none}
32 </style>
33 <script type=
"text/javascript">
34 function printpage() {
35 document.getElementById(
'printButton').style.visibility="hidden";
36 window.print();
37 document.getElementById(
'printButton').style.visibility="visible";
38 }
39 </script>
40 <body>
41 <input name=
"print" type="button" value="Print" id="printButton" onClick="printpage()">
42 <table width=
"100%" border="0" cellspacing="0" cellpadding="0">
43   <tr>
44     <td align=
"center">
45       <table width=
"595" border="0" cellspacing="0" cellpadding="0">
46        
47         <tr>
48           <td height=
"30" align="center"><strong>Sales Report </strong></td>
49         </tr>
50         <tr>
51           <td height=
"30" align="center">&nbsp;</td>
52         </tr>
53         <tr>
54           <td align=
"right"><table width="300" border="0" cellspacing="0" cellpadding="0">
55             <tr>
56               <td width=
"150"><strong>Total Sales </strong></td>
57               <td width=
"150">&nbsp;<?php echo $age = $db->queryUniqueValue("SELECT sum(subtotal) FROM stock_sales where count1=1 AND date BETWEEN '$fromdate' AND '$todate' ");?></td>
58             </tr>
59             <tr>
60               <td><strong>Received Amount</strong></td>
61               <td>&nbsp;<?php echo $age = $db->queryUniqueValue(
"SELECT sum(payment) FROM stock_sales where count1=1 AND date BETWEEN '$fromdate' AND '$todate' ");?></td>
62             </tr>
63             <tr>
64               <td width=
"150"><strong>Total OutStanding </strong></td>
65               <td width=
"150">&nbsp;<?php echo $age = $db->queryUniqueValue("SELECT sum(balance) FROM stock_sales where count1=1 AND date BETWEEN '$fromdate' AND '$todate' ");?></td>
66             </tr>
67           </table></td>
68         </tr>
69         <tr>
70           <td width=
"45"><hr></td>
71         </tr>
72         <tr>
73           <td height=
"20"><table width="100%" border="0" cellspacing="0" cellpadding="0">
74               <tr>
75                 <td width=
"45"><strong>From</strong></td>
76                 <td width=
"393">&nbsp;<?php echo $_GET['from_sales_date']; ?></td>
77                 <td width=
"41"><strong>To</strong></td>
78                 <td width=
"116">&nbsp;<?php echo $_GET['to_sales_date']; ?></td>
79               </tr>
80           </table></td>
81         </tr>
82         <tr>
83           <td width=
"45"><hr></td>
84         </tr>
85         <tr>
86           <td><table width=
"100%" border="0" cellspacing="0" cellpadding="0">
87               <tr>
88                 <td><strong>Date</strong></td>
89                 <td><strong>Sales ID </strong></td>
90                 <td><strong>Customer</strong></td>
91                 <td><strong>Paid</strong></td>
92                 <td><strong>Balance</strong></td>
93                 <td><strong>Total</strong></td>
94               </tr>
95               <tr>
96                 <td>&nbsp;</td>
97                 <td>&nbsp;</td>
98                 <td>&nbsp;</td>
99                 <td>&nbsp;</td>
100                 <td>&nbsp;</td>
101                 <td>&nbsp;</td>
102               </tr>
103               <?php
104               $result = $db->query(
"SELECT * FROM stock_sales where count1=1 AND date BETWEEN '$fromdate' AND '$todate' ");
105 while
($line = $db->fetchNextObject($result)) {
106 ?>
107             
108                 <tr>
109                 <td><?php $mysqldate=$line->date;
110         $phpdate = strtotime( $mysqldate );
111         $phpdate = date(
"d/m/Y",$phpdate);
112         echo $phpdate; ?></td>
113                 <td><?php echo $line->transactionid; ?></td>
114                 <td><?php echo $line->customer_id; ?></td>
115                 <td><?php echo $line->payment; ?></td>
116                 <td><?php echo $line->balance; ?></td>
117                 <td><?php echo $line->subtotal; ?></td>
118               </tr>
119                 
120
121 <?php
122 }
123               ?>
124           </table></td>
125         </tr>
126         <tr>
127           <td>&nbsp;</td>
128         </tr>
129         <tr>
130           <td>&nbsp;</td>
131         </tr>
132     </table></td>
133   </tr>
134 </table>
135
136 </body>
137 </html>
138 <?php
139 }

140 else

141 echo
"Please from and to date to process report";
142 }
143 ?>


Gõ tìm kiếm nhanh...